package org.example.system.controller;

import org.example.system.entity.ExampleRoute;
import org.example.system.service.ExampleRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/exampleRoute")
public class ExampleRouteController {
    @Autowired
    private ExampleRouteService exampleRouteService;
    @GetMapping
    public List<ExampleRoute> getAll() { return exampleRouteService.findAll(); }
    @PostMapping
    public Map<String, Object> add(@RequestBody ExampleRoute route) {
        Map<String, Object> result = new HashMap<>();
        int row = exampleRouteService.add(route);
        result.put("success", row > 0);
        result.put("message", row > 0 ? "添加成功" : "添加失败");
        return result;
    }
    @DeleteMapping("/{id}")
    public Map<String, Object> delete(@PathVariable Long id) {
        Map<String, Object> result = new HashMap<>();
        int row = exampleRouteService.delete(id);
        result.put("success", row > 0);
        result.put("message", row > 0 ? "删除成功" : "删除失败");
        return result;
    }
} 